extends StaticBody3D
@onready var detection_area = $DetectionArea @onready var mesh = $MeshInstance3D
@export var highlight_color: Color = Color(1, 0.5, 0.5) @export var pulse_speed: float = 3.0 @export var selection_effect: PackedScene
var is_player_near: bool = false var is_being_looked_at: bool = false var default_material: StandardMaterial3D var current_tween: Tween
func _ready():
default_material = mesh.material_override.duplicate() mesh.material_override = default_material
detection_area.body_entered.connect(_on_body_entered) detection_area.body_exited.connect(_on_body_exited)
func _on_body_entered(body): if body.is_in_group("player"): is_player_near = true start_proximity_effect()
func _on_body_exited(body): if body.is_in_group("player"): is_player_near = false stop_proximity_effect()
func on_look_at(): is_being_looked_at = true start_look_effect() print(name, ": Player is looking at me!")
func on_look_away(): is_being_looked_at = false stop_look_effect() print(name, ": Player looked away")
func on_interact(): print(name, ": Player selected me!") apply_selection_effect()
get_tree().call_group("choice_system", "object_selected", self)
func start_proximity_effect():
if current_tween: current_tween.kill()
current_tween = create_tween().set_loops() current_tween.tween_property(mesh, "scale", Vector3(1.1, 1.1, 1.1), 1.0) current_tween.tween_property(mesh, "scale", Vector3.ONE, 1.0)
func stop_proximity_effect(): if current_tween: current_tween.kill() current_tween = null
create_tween().tween_property(mesh, "scale", Vector3.ONE, 0.3)
func start_look_effect():
var highlight_mat = default_material.duplicate() highlight_mat.emission_enabled = true highlight_mat.emission = highlight_color highlight_mat.emission_energy_multiplier = 1.5
mesh.material_override = highlight_mat
if current_tween: current_tween.kill()
current_tween = create_tween().set_loops() current_tween.tween_property(mesh, "scale", Vector3(1.2, 1.2, 1.2), 0.5) current_tween.tween_property(mesh, "scale", Vector3(1.1, 1.1, 1.1), 0.5)
func stop_look_effect(): mesh.material_override = default_material stop_proximity_effect()
func apply_selection_effect():
if selection_effect: var effect = selection_effect.instantiate() add_child(effect) effect.global_position = global_position effect.emitting = true